<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/include/nocache.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
		<script src="${pageContext.request.contextPath}/system/js/jquery-1.4.4.min.js" type="text/javascript"></script>
		<script type="text/javascript" charset="utf-8">
		    window.UEDITOR_HOME_URL = "${pageContext.request.contextPath}/editor/";
		</script>
	    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/editor/editor_config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/editor/editor_all.js"></script>
	    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/editor/themes/default/ueditor.css"/>
	</head>
	<body>
		所有草稿
		<select onchange="loadCG(this)">
			<option></option>
			<s:iterator value="cgList">
				<option value="<s:property value="id"/>"><s:property value="title"/></option>
			</s:iterator>
		</select>
		<div style="margin-top:15px;margin-left: 10px">
			<form method="post" onsubmit="return false" id="frm" action="${pageContext.request.contextPath}/blog/savecg.zhtml"/>
				<input type="hidden" name="base.id" id="blogid" value="<s:property value="base.id"/>"/>
				<input type="hidden" name="content.id" id="contentid" value="<s:property value="content.id"/>"/>
				<div style="display:none"><input id="editorcontent" name="content.content" value="<s:property value="content.content"/>"/></div>
			</form>
			<textarea id="editor" style="width:1000px;">
				<s:if test="content==null">
					<h3 style="border-bottom:#ccc 2px solid;text-align:center;margin:0px 0px 20px;font-size:32px;font-weight:bold;padding:0px 4px 0px 0px;">
    					[文章标题]
					</h3>				
				</s:if><s:else>
					<s:property value="content.content"/>				
				</s:else>
			</textarea>
			<br/>
			<input type="button" value="保存草稿" onclick="saveCG(1)"/><input type="button" value="提交发布" onclick="publishart()"/>
		</div>
		<script type="text/javascript">
			var editor=UE.getEditor('editor');
	    	function saveCG(){
	    		var content=UE.getEditor('editor').getContent();
	    		$("#editorcontent").val(content);
	    		var $form = $("#frm");
    			var param = $form.serializeArray();
    			$.post($form.attr("action"), param, function(data) {
    				var ids=data.split(",");
					$("#blogid").val(ids[0]);
					$("#contentid").val(ids[1]);
					alert("保存成功");
        		});
		    }
	    	//publishart
	    	function publishart(){
	    		var content=UE.getEditor('editor').getContent();
	    		$("#editorcontent").val(content);
	    		var $form = $("#frm");
    			var param = $form.serializeArray();
    			$.post("${pageContext.request.contextPath}/blog/publishart.zhtml", param, function(data) {
    				var url="${pageContext.request.contextPath}/blog/showart.zhtml?base.id="+data;
    				window.location=url;
        		});
		    }

		    function loadCG(select){
				if($.trim($(select).val())!=""){
					var url="${pageContext.request.contextPath}/blog/loadcg.zhtml?base.id="+$(select).val();
					alert(url);
					window.location=url;
				}
			}

		</script>
	</body>
</html>
